import time
import struct

class PacketBuilder:
    """
    [报文构建器类] - 构建创建各种类型的协议报文
    """
    def __init__(self):
        self._life_counter = 0
    def _increment_life(self):
        """
        [更新生命计数器] - 生命周期为0-255
        """
        self._life_counter = (self._life_counter % 255) + 1
        # time.sleep(0.5)
        return struct.pack('B', self._life_counter)
        # return self.life_counter

# 整数计数器类，用于生成连续的整数
class IntCounter:
    def __init__(self):
        self.count = 0
        self.max_val = 255
    
    def __call__(self):
        self.count = (self.count % self.max_val) + 1
        # time.sleep(1)
        return struct.pack('B', self.count)
        # return self.count

def app_1():
    pb = PacketBuilder()

    for i in range(257):
        print(pb._increment_life())

def app_2():
    counter = IntCounter()

    for i in range(257):
        print(counter())

def main():
    app_1()
    # app_2()

if __name__ == "__main__":
    main()